<template>
  <div>
    <!-- 顶部导航栏 -->
    <van-sticky :offset-top="0">
      <van-nav-bar
        title="地址管理"
        left-text="返回"
        left-arrow
        @click-left="onClickLeft"
      />
    </van-sticky>

    <van-address-list
      v-model="chosenAddressId"
      :list="list"
      default-tag-text="默认"
      @add="onAdd"
      @edit="onEdit"
      @select="onSelect"
    />
  </div>
</template>

<script>
import {
  deleteAction,
  detailAction,
  listAction,
  saveAction,
  getListAction,
} from "@/api/my/index";
import areaList from "@/assets/area";
export default {
  data() {
    return {
      chosenAddressId: "1",
      searchResult: [],
      addresslist: [],
      areaList,
      act: "add",
      list: [],
      datalist: [],
      money:''
    };
  },

  methods: {
    onSelect(content) {
      console.log(content);
      this.$router.push({
        name: "order",
        params: {
          data1: content,
          data2: this.datalist,
          price1:this.money,
        },
      });
    },
    // 添加收货地址
    onAdd() {
      this.$router.push({ name: "addaddress" });
    },
    // 修改收货地址
    onEdit(item, index) {
      this.$router.push({
        name: "editaddress",
        params: { data: this.addresslist[index] },
      });
    },
    onClickLeft() {
      this.$router.go(-1);
    },
    //切换默认收获地址
    onChangeDetail(val) {},
  },
  created() {
    this.datalist = this.$route.params.data;
    this.money = this.$route.params.price;
    getListAction({
      openId: localStorage.getItem("openId"),
    }).then((res) => {
      console.log(res);
      this.addresslist = res.data;
      res.data.forEach((el) => {
        var obj = {};
        obj.id = el.id;
        obj.name = el.name;
        obj.tel = el.mobile;
        obj.address = el.address + el.address_detail;
        obj.isDefault = el.is_default == 0 ? false : true;
        this.list.push(obj);
      });
    });
  },
};
</script>

<style scoped lang='less'>
</style>